package com.qk.mapper;


import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //1、动态条件分页查询用户列表
    List<User> getUsers(UserDto userDto);
    //2、添加用户
    /**
     * 插入用户信息
     *
     * @param user 用户实体
     */
    @Insert("INSERT INTO user(username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{name}, #{phone}, #{email}, #{gender}, #{status}, #{deptId}, #{roleId}, #{image}, #{remark}, #{createTime}, #{updateTime})")
    void insert(User user);
    //3、删除用户
    void deleteUser(List<Integer> ids);
    //4、修改用户
    @Update("UPDATE user SET username=#{username}, password=#{password}, name=#{name}, phone=#{phone}, email=#{email}, gender=#{gender}, status=#{status}, dept_id=#{deptId}, role_id=#{roleId}, image=#{image}, remark=#{remark}, update_time=#{updateTime} WHERE id=#{id}")
    void update(User user);
    //5、根据id查询用户
    @Select("SELECT * FROM user WHERE id=#{id}")
    User selectById(Integer id);
//6、根据角色查询用户[页面怎么调试]
    @Select("select user.* from user , role where user.role_id = role.id and role.label = #{label}")
    List<User> getByRoleLabel(String label);
//用户登录
    @Select("select u.*, r.label as role_label from user u left join role r on u.role_id = r.id where u.username = #{username};")
    User selectByUsername(String username);
}
